package com.macro.mall.portal.service.impl;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.PmsCommentLabel;
import com.macro.mall.model.PmsCommentLabelContent;
import com.macro.mall.model.PmsCommentOrder;
import com.macro.mall.model.PmsCommentViewFile;
import com.macro.mall.portal.dao.PmsCommentLabelContentMapper;
import com.macro.mall.portal.dao.PmsCommentLabelMapper;
import com.macro.mall.portal.dao.PmsCommentOrderMapper;
import com.macro.mall.portal.dao.PmsCommentViewFileMapper;
import com.macro.mall.portal.domain.PmsCommentOrderReq;
import com.macro.mall.portal.service.PmsCommentOrderService;
import com.macro.mall.portal.util.OssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author：贾维斯
 * @Description: 描述
 * @name：PmsCommentOrderServiceImpl
 * @Date：2024/10/30 16:28
 */
@Service
@Slf4j
public class PmsCommentOrderServiceImpl implements PmsCommentOrderService {
    @Autowired
    private PmsCommentOrderMapper pmsCommentOrderMapper;
    @Autowired
    private PmsCommentLabelContentMapper pmsCommentLabelContentMapper;
    @Autowired
    private PmsCommentLabelMapper pmsCommentLabelMapper;
    @Autowired
    private PmsCommentViewFileMapper pmsCommentViewFileMapper;



    @Override
    public void addCommentOrder(PmsCommentOrderReq pmsCommentOrderReq) {
        try {
            //添加评论表
            //评论对象
            PmsCommentOrder pmsCommentOrder = pmsCommentOrderReq.getPmsCommentOrder();
            //添加评论
            pmsCommentOrderMapper.addCommentOrder(pmsCommentOrder);
            //评论主键cid
            Integer cid = pmsCommentOrder.getCid();
            //标签id集合
            List<String> ids = pmsCommentOrderReq.getIds();
            //添加中间表
            pmsCommentLabelContentMapper.addCommentContent(cid,ids);
            //添加文件图片
            //获取图片对象
            List<String> pmsCommentViewFile = pmsCommentOrderReq.getPmsCommentViewFile();
            //添加文件

            pmsCommentViewFileMapper.addFile(pmsCommentViewFile);

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.info("休眠异常");
        }
    }

    /**
     * 添加中间表
     * @param cid
     * @param ids
     */
    @Async
    public void addContent(Integer cid,List<String> ids) {
        try {
            pmsCommentLabelContentMapper.addCommentContent(cid,ids);
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.info("谁死了？");
        }
    }

    /**
     * 文件图片
     * @param pmsCommentViewFile
     * @param
     */
    @Async
    public void addFiles(List<String> pmsCommentViewFile) {
        try {
            pmsCommentViewFileMapper.addFile(pmsCommentViewFile);
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.info("睡死了？");
        }
    }


    @Override
    public void addCommentLabel(PmsCommentLabel pmsCommentLabel) {
        //添加标签信息
        pmsCommentLabelMapper.addCommentLabel(pmsCommentLabel);
    }

    @Override
    public void addFile(List<String> pmsCommentViewFile) {
        //添加文件视图信息
        pmsCommentViewFileMapper.addFile(pmsCommentViewFile);
    }

    @Override
    public CommonResult<PmsCommentOrder> findComment(Integer skuId) {
        return pmsCommentOrderMapper.findComment(skuId);
    }
}
